package action;

import dao.UserDao;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import po.User;

@WebServlet(urlPatterns = "/user/action/CheckUnameServlet")
public class CheckUnameServlet extends HttpServlet {
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String uname = req.getParameter("uname");
        if (uname != null) {
            User user = new User();
            user.setUname(uname);
            user.setRole(0);
            UserDao userDao = new UserDao();
            User user1 = userDao.selectByUname(user);
            boolean isExisting = false;
            if (user1 != null) {
                isExisting = true;
            }

            PrintWriter out = null;

            try {
                out = resp.getWriter();
                if (isExisting) {
                    out.write("yes");
                } else {
                    out.write("no");
                }
            } catch (IOException var18) {
                var18.printStackTrace();
            } finally {
                try {
                    out.close();
                } catch (Exception var17) {
                    var17.printStackTrace();
                }

            }
        }

    }
}
